package cn.oracle.eshop.auth.dao.impl;

import cn.oracle.eshop.auth.dao.PriorityDAO;
import cn.oracle.eshop.auth.domain.PriorityDo;
import cn.oracle.eshop.auth.mapper.PriorityDoMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.util.List;

/** 权限管理模块的DAO组件
 * @author wyh
 * @ClassName PriorityDAOImpl
 * @date 2022/1/12 /22:04
 */
@Repository
@Slf4j
public class PriorityDAOImpl implements PriorityDAO {
    /**权限管理模块的mapper组件*/
    @Autowired
    private PriorityDoMapper priorityDoMapper;
    /****
     *查询根权限
     * @author wyh
     * @date 2022/1/12
     * @param
     * @return 根权限集合
    */

    @Override
    public List<PriorityDo> listRootPriorites() {
        try {
            return priorityDoMapper.listRootPriorites();
        } catch (Exception e) {
            log.error("error:{}",e);
        }
        return null;

    }

    @Override
    public List<PriorityDo> listChildPriorities(Long parentId) {

        try {
          return   priorityDoMapper.listChildPriorities(parentId);
        } catch (Exception e) {
           log.error("error:{}",e);
        }
        return null;
    }

    @Override
    public Boolean removePriority(Long id) {
        try {
            priorityDoMapper.removePriority(id);
        } catch (Exception e) {
           log.error("删除error:{}",e);
           return false;
        }
        return  true;
    }

    @Override
    public Boolean savePriority(PriorityDo priorityDo) {
        try {
             priorityDoMapper.savePriority(priorityDo);
        } catch (Exception e) {
            log.error("saveError:{}",e);
            return false;
        }
        return true;
    }

    @Override
    public Boolean updatePriorityDo(PriorityDo priorityDo) {
        try {
            priorityDoMapper.updatePriorityDo(priorityDo);
        } catch (Exception e) {
            log.error("updateError:{}", e);
            return false;

        }
        return true;
    }

    @Override
    public PriorityDo getPriorityById(long id) {
        try {
            return priorityDoMapper.getPriorityById(id);
        } catch (Exception e) {
            log.error("getError：{}",e);
        }
        return null;
    }
}
